import axios from 'axios'

const request = axios.create({
    baseURL:'http://localhost:9090',
    timeout:5000
})
//request拦截器
//可以自请求发送前对请求做一些处理
//比如统一加token
request.interceptors.request.use(config => {
    config.headers['Content-Type'] = 'application/json;charset=UTF-8';
    return config
}, error => {
    return Promise.reject(error);

});

request.interceptors.response.use(response => {
    let res = response.data;
    //兼容服务端返回的字符串数据
    if(typeof res.data === 'string'){
        res =res ?JSON.parse(res) : res;
    }
    return res;
    },
    error=> {
        console.log('err'+error)
        return Promise.reject(error);
    })

export default request;